home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / catD / poll.z / poll
Encoding:
Text File  |  2002-10-03  |  13.7 KB  |  197 lines

  1.  
  2.  
  3.  
  4. ppppoooollllllll((((DDDD2222))))                                                              ppppoooollllllll((((DDDD2222))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _pppp_oooo_llll_llll - poll entry point for a non-STREAMS character driver
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_yyyy_ssss_////_pppp_oooo_llll_llll_...._hhhh_>>>>
  13.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_yyyy_ssss_////_dddd_dddd_iiii_...._hhhh_>>>>
  14.      _iiii_nnnn_tttt _p_r_e_f_i_x_pppp_oooo_llll_llll_((((_dddd_eeee_vvvv______tttt _d_e_v_,,,, _ssss_hhhh_oooo_rrrr_tttt _e_v_e_n_t_s_,,,, _iiii_nnnn_tttt _a_n_y_y_e_t_,,,, _ssss_hhhh_oooo_rrrr_tttt _****_r_e_v_e_n_t_s_p_,,,,
  15.           _ssss_tttt_rrrr_uuuu_cccc_tttt _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd _****_****_p_h_p_p_,,,, _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _iiii_nnnn_tttt _****_g_e_n_p_))))_;;;;
  16.  
  17.    AAAArrrrgggguuuummmmeeeennnnttttssss
  18.      _d_e_v       The device number for the device to be polled.
  19.  
  20.      _e_v_e_n_t_s    Mask (bit-wise _OOOO_RRRR) indicating the events being polled.
  21.  
  22.      _a_n_y_y_e_t    A flag that indicates whether the driver should return a
  23.                pointer to its _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure and the value of the
  24.                pollhead's generation number to the caller.
  25.  
  26.      _r_e_v_e_n_t_s_p  A pointer to a bitmask of the returned events satisfied.
  27.  
  28.      _p_h_p_p      A pointer to a pointer to a _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure (defined in
  29.                _ssss_yyyy_ssss_////_pppp_oooo_llll_llll_...._hhhh).
  30.  
  31.      _g_e_n_p      A pointer to an unsigned integer that is used by the driver to
  32.                store the current value of the pollhead's generation number at
  33.                the time of the poll.
  34.  
  35. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  36.      The _pppp_oooo_llll_llll entry point indicates whether certain I/O events have occurred
  37.      on a given device.  It must be provided by any non-STREAMS character
  38.      device driver that wishes to support polling [see _pppp_oooo_llll_llll(2)].
  39.  
  40.    RRRReeeettttuuuurrrrnnnn VVVVaaaalllluuuueeeessss
  41.      The _pppp_oooo_llll_llll routine should return 0 for success, or the appropriate error
  42.      number.
  43.  
  44. UUUUSSSSAAAAGGGGEEEE
  45.      This entry point is optional, and is valid for character device drivers
  46.      only.
  47.  
  48.      Valid values for _e_v_e_n_t_s are:
  49.  
  50.           _PPPP_OOOO_LLLL_LLLL_IIII_NNNN        Data is available to be read (either normal or out-
  51.                         of-band).
  52.  
  53.           _PPPP_OOOO_LLLL_LLLL_OOOO_UUUU_TTTT       Data may be written without blocking.
  54.  
  55.           _PPPP_OOOO_LLLL_LLLL_PPPP_RRRR_IIII       High priority data are available to be read.
  56.  
  57.  
  58.  
  59.  
  60.  
  61.                                                                         PPPPaaaaggggeeee 1111
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. ppppoooollllllll((((DDDD2222))))                                                              ppppoooollllllll((((DDDD2222))))
  69.  
  70.  
  71.  
  72.           _PPPP_OOOO_LLLL_LLLL_HHHH_UUUU_PPPP       A device hangup.
  73.  
  74.           _PPPP_OOOO_LLLL_LLLL_EEEE_RRRR_RRRR       A device error.
  75.  
  76.           _PPPP_OOOO_LLLL_LLLL_RRRR_DDDD_NNNN_OOOO_RRRR_MMMM    Normal data is available to be read.
  77.  
  78.           _PPPP_OOOO_LLLL_LLLL_WWWW_RRRR_NNNN_OOOO_RRRR_MMMM    Normal data may be written without blocking (same as
  79.                         _PPPP_OOOO_LLLL_LLLL_OOOO_UUUU_TTTT).
  80.  
  81.           _PPPP_OOOO_LLLL_LLLL_RRRR_DDDD_BBBB_AAAA_NNNN_DDDD    Out-of-band data is available to be read.
  82.  
  83.           _PPPP_OOOO_LLLL_LLLL_WWWW_RRRR_BBBB_AAAA_NNNN_DDDD    Out-of-band data may be written without blocking.
  84.  
  85.      A driver that supports polling must provide a _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure for each
  86.      minor device supported by the driver.  On systems where they are
  87.      available, the driver should use the _pppp_hhhh_aaaa_llll_llll_oooo_cccc(D3) function to allocate the
  88.      _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure, and use the _pppp_hhhh_ffff_rrrr_eeee_eeee(D3) function to free the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd
  89.      structure, if necessary.
  90.  
  91.      The _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure must be initialized to zeros prior to its first
  92.      use (when _pppp_hhhh_aaaa_llll_llll_oooo_cccc is used to allocate the structure, this is done
  93.      automatically).
  94.  
  95.      The definition of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure is not included in the DDI/DKI,
  96.      and can change across releases.  It should be treated as a ``black box''
  97.      by the driver; none of its fields may be referenced.  Although the size
  98.      of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure is guaranteed to remain the same across
  99.      releases, it is good practice for drivers not to depend on the size of
  100.      the structure.
  101.  
  102.      The driver must implement the polling discipline itself.  Each time the
  103.      driver detects a pollable event, it should call _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3), passing
  104.      to it the event that occurred and the address of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure
  105.      associated with the device.  Note that _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp should be called with
  106.      only one event at a time.
  107.  
  108.      When the driver's _pppp_oooo_llll_llll entry point is called, the driver should check if
  109.      any of the events requested in _e_v_e_n_t_s have occurred.  The driver should
  110.      store the mask, consisting of the subset of _eeee_vvvv_eeee_nnnn_tttt_ssss that are pending, in
  111.      the _ssss_hhhh_oooo_rrrr_tttt pointed to by _r_e_v_e_n_t_s_p.  Note that this mask may be 0 if none
  112.      of the events are pending.  In this case, the driver should check the
  113.      _a_n_y_y_e_t flag and, if it is zero, store the address of the device's
  114.      _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd structure in the pointer pointed at by _p_h_p_p and also store the
  115.      value of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd's generation number at the time of the poll in the
  116.      unsigned integer pointed to by _g_e_n_p.
  117.  
  118.      The pollhead's generation value must be sampled either while a state lock
  119.      is held that will hold off any call to _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3) on the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd by
  120.      the lower portion of the driver, or it must be taken _b_e_f_o_r_e the check is
  121.      made for any pending events; _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3) increments the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd's
  122.      generation number each time it is called.  The generation number is used
  123.      to solve the race condition that exists for the caller of the poll()
  124.  
  125.  
  126.  
  127.                                                                         PPPPaaaaggggeeee 2222
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. ppppoooollllllll((((DDDD2222))))                                                              ppppoooollllllll((((DDDD2222))))
  135.  
  136.  
  137.  
  138.      routine between the time that the driver's poll() routine is called and
  139.      when the caller adds itself to the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd's waiter queue.  When the
  140.      poll() routine is called, there may be no events of interest pending and
  141.      the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd is returned by the driver poll() routine in order that the
  142.      caller can queue itself onto the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd to wait for such events.  If
  143.      the lower layer of the driver signals such an event via a call to
  144.      _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3) before the caller can queue up, the caller may block
  145.      forever or wait unnecessarily for the next such event before being woken
  146.      up.  The snapshot of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd's generation number at the time of the
  147.      poll allows the caller to check the generation number of the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd as
  148.      it is about to queue itself up.  If the snapshot value returned by the
  149.      driver and the current generation number match, the caller can safely
  150.      queue itself up.  If they don't match, the caller knows that it must
  151.      retry the poll() operation since at least one call to _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3) must
  152.      have occurred on the _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd.
  153.  
  154.      The canonical _pppp_oooo_llll_llll() algorithm is:
  155.      _////_**** _ssss_nnnn_aaaa_pppp_ssss_hhhh_oooo_tttt _pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd _gggg_eeee_nnnn_eeee_rrrr_aaaa_tttt_iiii_oooo_nnnn _nnnn_uuuu_mmmm_bbbb_eeee_rrrr _bbbb_eeee_ffff_oooo_rrrr_eeee _cccc_hhhh_eeee_cccc_kkkk_iiii_nnnn_gggg _eeee_vvvv_eeee_nnnn_tttt_ssss _****_////
  156.      _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _iiii_nnnn_tttt _gggg_eeee_nnnn _==== _PPPP_OOOO_LLLL_LLLL_GGGG_EEEE_NNNN_((((_mmmm_yyyy______llll_oooo_cccc_aaaa_llll______pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd______pppp_oooo_iiii_nnnn_tttt_eeee_rrrr_))))_;;;;
  157.      _iiii_ffff _((((_eeee_vvvv_eeee_nnnn_tttt_ssss______aaaa_rrrr_eeee______ssss_aaaa_tttt_iiii_ssss_ffff_iiii_eeee_dddd______nnnn_oooo_wwww_)))) _{{{{
  158.           _****_r_e_v_e_n_t_s_p _==== _eeee_vvvv_eeee_nnnn_tttt_ssss _&&&& _mmmm_aaaa_ssss_kkkk______oooo_ffff______ssss_aaaa_tttt_iiii_ssss_ffff_iiii_eeee_dddd______eeee_vvvv_eeee_nnnn_tttt_ssss_;;;;
  159.      _}}}} _eeee_llll_ssss_eeee _{{{{
  160.           _****_r_e_v_e_n_t_s_p _==== _0000_;;;;
  161.           _iiii_ffff _((((_!!!!_a_n_y_y_e_t_)))) _{{{{
  162.                _****_p_h_p_p _==== _mmmm_yyyy______llll_oooo_cccc_aaaa_llll______pppp_oooo_llll_llll_hhhh_eeee_aaaa_dddd______pppp_oooo_iiii_nnnn_tttt_eeee_rrrr_;;;;
  163.                _****_g_e_n_p _==== _gggg_eeee_nnnn_;;;;
  164.           _}}}}
  165.      _}}}}
  166.      _rrrr_eeee_tttt_uuuu_rrrr_nnnn _((((_0000_))))_;;;;
  167.    SSSSyyyynnnncccchhhhrrrroooonnnniiiizzzzaaaattttiiiioooonnnn CCCCoooonnnnssssttttrrrraaaaiiiinnnnttttssss
  168.      On uniprocessor systems, user context is available in the _pppp_oooo_llll_llll routine,
  169.      but if the driver sleeps, it must do so such that signals do not cause
  170.      the sleep to longjump [see _ssss_llll_eeee_eeee_pppp(D3)].
  171.  
  172.      On multiprocessor systems, the _pppp_oooo_llll_llll routine may not call any function
  173.      that sleeps.
  174.  
  175. RRRREEEEFFFFEEEERRRREEEENNNNCCCCEEEESSSS
  176.      _bbbb_zzzz_eeee_rrrr_oooo(D3), _pppp_hhhh_aaaa_llll_llll_oooo_cccc(D3), _pppp_hhhh_ffff_rrrr_eeee_eeee(D3), _pppp_oooo_llll_llll(2), _pppp_oooo_llll_llll_wwww_aaaa_kkkk_eeee_uuuu_pppp(D3), _ssss_eeee_llll_eeee_cccc_tttt(2)
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.                                                                         PPPPaaaaggggeeee 3333
  192.  
  193.  
  194.  
  195.